package day11;

import java.util.Objects;

public class TestObject2 {
    public static void main(String[] args) {
        Student2 s = new Student2("张三",19);
        Student2 s2 = new Student2("张三",19);
        System.out.println(s);
        System.out.println(s.hashCode());
        System.out.println(s.equals(s2));
    }
}
class Student2{
    String name;
    int age;

    public Student2(String name, int age) {
        this.name = name;
        this.age = age;
    }

    @Override
    public String toString() {
        return "Student2{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Student2 student2 = (Student2) o;
        return age == student2.age && Objects.equals(name, student2.name);
    }

}